package com.renren.faceos.door;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private DoorJNI doorJNI;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button open = findViewById(R.id.open);
        Button close = findViewById(R.id.close);
        Button status = findViewById(R.id.status);
        open.setOnClickListener(this);
        close.setOnClickListener(this);
        status.setOnClickListener(this);
        doorJNI = new DoorJNI();

        //JnaDoor.INSTANTCE.AL_InitAll();
//    File file = new File("/sys/class/gpio/gpio234/value");
//        try {
//            FileOutputStream out = new FileOutputStream(file);
//            byte[] t = new byte[1024];
//            out.write(t);
//            Log.d("tag",t.toString());
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
    }


    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.open:

                int ret = doorJNI.init();

                toast("init" + ret);
                //int open = doorJNI.open();
                //toast("开门" + open);

//                int status = JnaDoor.INSTANTCE.AL_CheckDoorStatus(1);
//                if(status == 0)
//                {
//                    JnaDoor.INSTANTCE.AL_OpenDoor(1);
//                }
//                if(status == 1)
//                {
//                    JnaDoor.INSTANTCE.AL_CloseDoor(1);
//                }

                break;
            case R.id.close:
                //int close = doorJNI.close();
                //toast("关门"+close);
                break;
            case R.id.status:
                //int status = doorJNI.status();
                //toast("门状态"+status);
                break;
        }
    }

    private void toast(String text) {
        Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
    }
}
